<?php
//session_start();
class Identification extends Model {
	
    function Identification()
    {
        parent::Model();

    }
	
	
	
	//function insert()
	function insert($Mail, $Nom, $Prenom, $MDP)
	{
		/*$Mail		= mysql_real_escape_string($mailNew);
		$Nom		= mysql_real_escape_string($nomNew);
		$Prenom		= mysql_real_escape_string($prenomNew);
		$MDP		= mysql_real_escape_string($passwordNew);*/
		$date		= time();
		
		$sql = "INSERT INTO USER (ID, MAIL, DATEINS, DATECO, NOM, PRENOM, MDP)
		        VALUES ('',
					'".$Mail."',
					'".$date."',
					'".$date."',
					'".$Nom."',
					'".$Prenom."',
					'".$MDP."'
				)";
		$this->db->query($sql);
			$_SESSION['mail'] = $Mail;
			$_SESSION['ID'] = mysql_insert_id();
			$_SESSION['nom'] = $Nom;
			$_SESSION['prenom'] = $Prenom;
			$data['title'] = "Profil";
			
			$this->load->view('render/identifier', $data);
		return mysql_insert_id();
	}
	function Update($Mail, $Nom, $Prenom, $MDP)
	{
		
		$_SESSION['mail'] = $Mail;
		
		$_SESSION['nom'] = $Nom;
		$_SESSION['prenom'] = $Prenom;
		$sql = "UPDATE USER SET MAIL = '".$Mail."',NOM = '".$Nom."',PRENOM ='".$Prenom."',MDP = '".$MDP."' WHERE ID = '".$_SESSION['ID']."'";
		$this->db->query($sql);
		$data['title'] = "Profil";
		echo "Modification(s) effectuées";	
		$this->load->view('render/identifier', $data);
		
	}
	function Log($Mail, $MDP)
	{
		$sql = "SELECT * FROM USER WHERE MAIL = '".$Mail."' AND MDP = '".$MDP."'";
		$this->db->query($sql);
		$query = $this->db->query($sql);
		
		if (!empty($query->row()->ID))
		
		{	
			
			$_SESSION['mail'] = $query->row()->MAIL;
			$_SESSION['ID'] = $query->row()->ID;
			$_SESSION['nom'] = $query->row()->NOM;
			$_SESSION['prenom'] = $query->row()->PRENOM;
			$data['title'] = "Profil";
			
			$this->load->view('render/identifier', $data);
		}
		else
		{
			$data['title'] = "Profil";
			echo "Erreur lors de l'identification";
			$this->load->view('render/user', $data);
		}
	}
	
}
?>
